package core.network.client2game.handler.nn;

import java.io.IOException;

import business.player.Player;

import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.exception.WSException;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;

import core.network.client2game.handler.PlayerHandler;

public class CNNKongZhi extends PlayerHandler {

    @Override
    public void handle(Player player, WebSocketRequest request, String message) throws WSException, IOException {
        final IntWrapper req = new Gson().fromJson(message, IntWrapper.class);	
		
		if(req.type == 0){
			if(player.isGmLevel()){
				request.response("GM");
			}
			else{
				request.error(ErrorCode.NotAllow, "noGm");
			}
		}
		else if(req.type == 1){
			player.setKongzhidian(req.dianshu);
			int total = player.getKongzhidian();
			System.out.println("设置控制点: " + total);
			if (total == req.dianshu) {
				request.response("操作成功");
				return;
			}
			else{
				request.error(ErrorCode.NotAllow, "操作失败");
			}	
		}		
    }

}

class IntWrapper {
	int type;
    int dianshu;
    // 构造函数、getter 和 setter 省略
}
